package src.main.yuanxing;

import java.io.Serializable;

public class ShallowCopyTest {

    public static void main(String[] args) {
        Person person = new Person("张三", "男");
        ShallowCopy shallowCopy = new ShallowCopy("西瓜", person);
        try {
            ShallowCopy copy = (ShallowCopy) shallowCopy.clone();
            System.out.println("原值地址 : " + shallowCopy);
            System.out.println("拷贝值地址 : " + copy);
            System.out.println("原值TYPE : " + shallowCopy.getType());
            System.out.println("拷贝值TYPE : " + copy.getType());
            System.out.println("原值PERSON : " + shallowCopy.getPerson());
            System.out.println("拷贝值PERSON : " + copy.getPerson());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
//原对象
class Person implements Serializable {

    private String name;
    private String gender;

    public Person(String name, String gender) {
        this.name = name;
        this.gender = gender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }
}
//浅拷贝
class ShallowCopy implements Cloneable{

    private String type;
    private Person person;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public ShallowCopy(String type, Person person) {
        this.type = type;
        this.person = person;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}